const app = getApp();
import { logger } from '@/utils/util'
Component({
    properties: {
        componentData: {
            type: Object,
            value: {} // 修正默认值定义  
        }
    },
    observers: {
        'componentData': function (value) {
            console.log(value)
            if (value) {
                if(value.watch_electronic_fence_list) {
                    value.pointsStr = value.watch_electronic_fence_list.map(item => {
                        return `(${item.ele_fence_precision},${item.ele_fence_latitude})`
                    })
                    value.pointsStr = value.pointsStr.join(',');
                }
                this.setData({
                    ...value
                })
            }
        }
    },
    data: {
        staticPrefix: app.globalData.STATIC_PREFIX,
        /**
         * 心率设置
         * @params {Number} is_heart_blood 心率上报开关 [0 关 - 1 开]
         * @params {Number} heart_blood_frequency 心率上报频率
         * @params {Number} is_heart_rate 心率预警设置开关 [0 关 - 1 开]
         * @params {Number} heart_rate_up 心率预警上限
         * @params {Number} heart_rate_down 心率预警下限
         * */
        is_heart_blood: false,
        heart_blood_frequency: 5,
        is_heart_rate: false,
        heart_rate_up: 40,
        heart_rate_down: 40,
        /**
         * 计步设置
         * @params {Number} is_step_gauge 计步上报开关 0/1
         * @params {Number} step_gauge_frequency 计步上报频率
         * @params {Number} is_step_meter 计步预警开关
         * @params {Number} step_meter_target 计步目标值
         * */
        is_step_gauge: false,
        step_gauge_frequency: 10,
        is_step_meter: false,
        step_meter_target: 0,
        /**
         * 位置设置
         * @params {Number} is_position_report 位置上报开关 0/1
         * @params {Number} position_report_frequency 位置上报频率 
         * */
        is_position_report: false,
        position_report_frequency: 5,
        /**
         * 低电量设置
         * @params {Number} is_low_power 低电量上报开关 0/1
         * */
        is_low_power: false,
        /**
         * 血氧设置
         * @params {Number} is_blood_oxygen 血氧预警开关
         * @params {Number} blood_oxygen_value 血氧预警值
         * */
        is_blood_oxygen: false,
        blood_oxygen_value: 0,
        /**
         * 体温设置 仅X1设备支持
         * @params {Number} id_body_temperature 0/1
         * @params {Number} body_temperature_value
         * @params
         * */
        body_temperature_report: false,
        id_body_temperature: false,
        body_temperature_frequency: 5,
        body_temperature_value: 37,

        watch_electronic_fence_list: [],
    },
    methods: {
        onSleepClick(e) {
            this.setData({
                sleep_tag: e.currentTarget.dataset.tag,
                time_show: true
            })
        },
        onSleepConfirm(e) {
            this.setData({
                [`sleep_data_${this.data.sleep_tag}_date`]: e.detail,
                time_show: false
            })
        },
        onSleepCancel() {
            this.setData({
                time_show: false
            })
        },
        onSliderChange(e) {
            console.log(e)
            this.setData({
                [e.currentTarget.dataset.type]: e.detail
            })
        },
        onChange(e) {
            const {
                type
            } = e.currentTarget.dataset;
            if (type && this.data.hasOwnProperty(type)) {
                this.setData({
                    [`${type}`]: !this.data[`${type}`]
                });
            } else {
                logger.error(`参数不存在`);
            }
        },
        onBloodChange(e) {
            this.setData({
                heart_rate_down: e.detail[0],
                heart_rate_up: e.detail[1]
            })
        },
        onLpChange(e) {
            this.setData({
                // low_pressure_range_down: e.detail[0],
                low_pressure_range_up: e.detail
            })
        },
        onHpChange(e) {
            this.setData({
                // high_pressure_range_down: e.detail[0],
                high_pressure_range_up: e.detail
            })
        },
        onStepChange(e) {
            this.setData({
                [`${e.currentTarget.dataset.type}`]: e.detail
            })
        },
        onNavigate() {
            this.triggerEvent('navigate')
        },
    }
})